---
title: 20250116 - Use DMMF for Prisma Schema Parsing
---

## Status

- [ ] Proposed
- [x] Accepted
- [ ] Rejected
- [ ] Deprecated
- [ ] Superseded

## Context

We need to parse Prisma schema files to extract schema information. Several approaches were considered:

1. JavaScript parsers (e.g., Acorn, Babel)
2. Custom parsers using parser generators (e.g., PEG.js)
3. [DMMF (Data Model Meta Format)](https://github.com/prisma/prisma/blob/main/ARCHITECTURE.md#the-dmmf-or-data-model-meta-format) from @prisma/internals

Each approach has different implications for maintenance, accuracy, and development effort. JavaScript parsers were immediately ruled out as they are designed for parsing JavaScript code, not Prisma's custom schema format.

## Decision

We will use DMMF from @prisma/internals to parse Prisma schema files. DMMF is Prisma's internal representation format used for schema parsing and validation. Using DMMF is more reliable and accurate for parsing Prisma schema files compared to custom parsers.

Key factors in this decision:

- Official support from Prisma team
- Comprehensive parsing of models, fields, and relationships
- Built-in validation and type safety
- Automatic compatibility with future Prisma updates
- De facto stability demonstrated by widespread usage in the Prisma ecosystem

## Consequences

### Positive

- Reliable and accurate parsing of Prisma schemas
- Reduced development and maintenance effort (no need to implement custom parsers)
- Future-proof against Prisma syntax changes
- Proven stability through widespread usage in other tools
  - [Prisma Editor](https://github.com/mohammed-bahumaish/prisma-editor)
  - [Prisma ERD Visualizer](https://github.com/skn0tt/prisma-erd)
  - [prisma-uml](https://github.com/emyann/prisma-uml)
  - [DBML Generator](https://github.com/notiz-dev/prisma-dbml-generator)
  - [Prismaliser - Visualise your Prisma schema models and relations](https://prismaliser.app/)
  - [Prisma Editor - A powerful tool to visualize and edit Prisma Schema](https://github.com/mohammed-bahumaish/prisma-editor)

### Negative

- Additional dependency on @prisma/internals
- No official recommendation to use @prisma/internals
  - ref: [Discussion about @prisma/sdk rename to @prisma/internals](https://github.com/prisma/prisma/issues/13877)

### Neutral

- Need to transform DMMF output to match our internal schema format
- Learning curve for working with DMMF API
